package com.ourteam.system.api;

import com.ourteam.frame.web.AbstractTreeNodeBuilder;
import com.ourteam.system.domain.SystemAction;
import com.ourteam.system.domain.SystemModule;
import com.ourteam.system.service.ISystemApplicationService;
import com.ourteam.system.service.SystemApplicationServiceFactory;

public class SystemModuleActionNodeBuilder extends AbstractTreeNodeBuilder<SystemModule, SystemAction> {

	private final static ISystemApplicationService applicationService = SystemApplicationServiceFactory
			.getSystemApplicationService();

	@Override
	public SystemAction[] getTreeNodeObjects(SystemModule parentObject) throws Exception {
		return applicationService.getSystemActions(parentObject.getId());
	}

	@Override
	public Object getNodeId(SystemAction childObject) {
		return childObject.getId();
	}

	public boolean isLeaf(SystemAction childObject) {
		return true;
	}

	@Override
	public String getNodeDefineId(SystemAction childObject) throws Exception {
		return "sysAction";
	}

	@Override
	public SystemModule converToParentObject(Object parent) throws Exception {
		return applicationService.getSystemModuleById(Long.parseLong(parent.toString()));
	}

	@Override
	public int getChildCount(SystemAction childObject) throws Exception {
		return 0;
	}

}
